package pt.iul.dcti.poo.financemanager.categories;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Category {

	String name;
	private ArrayList<String> descriptions = new ArrayList<String>();
	
	public Category(String name) {
		this.name = name;
	}

	public static List<Category> readCategories(String fileName) {	
		List<Category> listaCategorias = new ArrayList<Category>();
		Scanner s;
		try {
			s = new Scanner(new File(fileName));
//			Scanner s = new Scanner(fileName);
			while(s.hasNext()){
				String line = s.nextLine();
				String[] separador = line.split(";");
				Category c = new Category(separador[0].trim());
				if(!separador[1].isEmpty()){
					String[] sep = separador[1].split(",");
					for(int i = 0; i < sep.length; i++){
						c.addDescription(sep[i]);
					}
				}
				listaCategorias.add(c);
				
			}
			s.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		return listaCategorias;
	}

	public boolean hasDescription(String description) {
		if(descriptions.contains(description))
			return true;
		return false;
	}

	public void addDescription(String description) {
		descriptions.add(description);
	}
	
	public String getName() {
		return name;
	}
	

}
